# -*- coding: utf-8 -*-
import json
import time
import requests
import pymysql




class Pricing(object):
    '''在本地生成最低价excel'''

    def __init__(self):

        self.title = 'ota_account'
        self.dingding_url = "https://oapi.dingtalk.com/robot/send?access_token=8f883e4b2723b1eefcb34fa73cbf6cebe47b3aa605e439216e04e73220b21134"
        self.batch_no = time.strftime('%Y%m%d%H', time.localtime(time.time()))
        HOST = 'oyo-scrapy-database.mysql.rds.aliyuncs.com'
        PORT = 3306
        USER = 'scrapy'
        PASSWD = 'Podf&T$2'
        DB = 'spider'
        CHARSET = 'utf8mb4'

        self.conn = pymysql.connect(host=HOST, port=PORT, user=USER, passwd=PASSWD, db=DB, charset=CHARSET)
        self.cur = self.conn.cursor()

    def send_dingding(self):
        msg_body = []
        url='http://v1-http-api.jsdama.com/api.php?mod=php&act=point'
        body={
            'user_name':'baozhengxing',
            'user_pw':'1qaz2wsx@123'
        }
        con=requests.post(url=url,data=body)
        con=con.content.decode()
        json_data=json.loads(con)
        count=json_data['data']
        print(count)
        msg_body.append('剩余数量:'+str(count))

        head_msg = " #### 验证码剩余点数 \n\n  ———————————————— \n\n "
        head_msg += "\n\n".join(msg_body)
        post_data = {'msgtype': 'markdown',
                     'markdown': {'title': self.title,
                                  'text': head_msg
                                  }
                     }
        headers = {'Content-Type': 'application/json; charset=utf-8'}
        requests.post(url=self.dingding_url, data=json.dumps(post_data), headers=headers)


if __name__ == "__main__":


    d = Pricing()
    d.send_dingding()
